From e4e6c374aa126d297f450348f3058bf1f31422fe Mon Sep 17 00:00:00 2001 From: "tsteven4@gmail.com" Date: Mon, 17 Feb 2014 15:16:34 +0000 Subject: [PATCH] More implementation for NEWQ. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4749 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/garmin.cc | 12 ++++++++++-- gpsbabel/lowranceusr4.cc | 14 ++++++++++++-- gpsbabel/radius.cc | 9 +++++++-- gpsbabel/tomtom.cc | 12 ++++++++++-- gpsbabel/waypt.cc | 20 ++++++++++++++++---- 5 files changed, 55 insertions(+), 12 deletions(-) diff --git a/gpsbabel/garmin.cc b/gpsbabel/garmin.cc index d5dd6a297..5d1a9d6cd 100644 --- a/gpsbabel/garmin.cc +++ b/gpsbabel/garmin.cc @@ -885,8 +885,12 @@ waypoint_prepare(void) { int i; int n = waypt_count(); +#if NEWQ + extern QList waypt_list; +#else queue* elem, *tmp; extern queue waypt_head; +#endif int icon; tx_waylist = (struct GPS_SWay**) xcalloc(n,sizeof(*tx_waylist)); @@ -897,12 +901,16 @@ waypoint_prepare(void) i = 0; +#if NEWQ + // Iterate with waypt_disp_all? + foreach(Waypoint* wpt, waypt_list) { +#else QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - Waypoint* wpt; + Waypoint* wpt = (Waypoint*) elem; +#endif char* ident; char obuf[256]; - wpt = (Waypoint*) elem; #if NEW_STRINGS QString src; if (!wpt->description.isEmpty()) { diff --git a/gpsbabel/lowranceusr4.cc b/gpsbabel/lowranceusr4.cc index e7a492c93..94d72ba61 100644 --- a/gpsbabel/lowranceusr4.cc +++ b/gpsbabel/lowranceusr4.cc @@ -32,7 +32,11 @@ /* from waypt.c, we need to iterate over waypoints when extracting routes */ +#if NEWQ +extern QList waypt_list; +#else extern queue waypt_head; +#endif static gbfile* file_in; static gbfile* file_out; @@ -473,12 +477,18 @@ lowranceusr4_parse_waypoints(void) static Waypoint* lowranceusr4_find_waypt(int uid_unit, int uid_seq_low, int uid_seq_high) { +#if !NEWQ queue* elem, *tmp; - Waypoint* waypointp; +#endif lowranceusr4_fsdata* fs = NULL; +#if NEWQ + // Iterate with waypt_disp_all? + foreach(Waypoint* waypointp, waypt_list) { +#else QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - waypointp = (Waypoint*) elem; + Waypoint* waypointp = (Waypoint*) elem; +#endif fs = (lowranceusr4_fsdata*) fs_chain_find(waypointp->fs, FS_LOWRANCEUSR4); if (fs && fs->uid_unit == uid_unit && diff --git a/gpsbabel/radius.cc b/gpsbabel/radius.cc index 840148d46..a177aad2f 100644 --- a/gpsbabel/radius.cc +++ b/gpsbabel/radius.cc @@ -109,8 +109,9 @@ dist_comp(const void* a, const void* b) void radius_process(void) { +#if !NEWQ queue* elem, * tmp; - Waypoint* waypointp; +#endif double dist; Waypoint** comp; int i, wc; @@ -120,7 +121,7 @@ radius_process(void) foreach(Waypoint* waypointp, waypt_list) { #else QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - waypointp = (Waypoint*)elem; + Waypoint* waypointp = (Waypoint*)elem; #endif dist = gc_distance(waypointp->latitude, waypointp->longitude, @@ -154,8 +155,12 @@ radius_process(void) * for qsort. */ +#if NEWQ + foreach(Waypoint* wp, waypt_list) { +#else QUEUE_FOR_EACH(&waypt_head, elem, tmp) { Waypoint* wp = (Waypoint*) elem; +#endif comp[i] = wp; waypt_del(wp); i++; diff --git a/gpsbabel/tomtom.cc b/gpsbabel/tomtom.cc index d6ffbcba7..22b55cead 100644 --- a/gpsbabel/tomtom.cc +++ b/gpsbabel/tomtom.cc @@ -434,9 +434,12 @@ data_write(void) { int ct = waypt_count(); struct hdr* htable, *bh; +#if NEWQ + extern QList waypt_list; +#else queue* elem, *tmp; extern queue waypt_head; - Waypoint* waypointp; +#endif double minlon = 200; double maxlon = -200; double minlat = 200; @@ -446,8 +449,13 @@ data_write(void) htable = (struct hdr*) xmalloc(ct * sizeof(*htable)); bh = htable; +#if NEWQ + // Iterate with waypt_disp_all? + foreach(Waypoint* waypointp, waypt_list) { +#else QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - waypointp = (Waypoint*) elem; + Waypoint* waypointp = (Waypoint*) elem; +#endif bh->wpt = waypointp; if (waypointp->longitude > maxlon) { maxlon = waypointp->longitude; diff --git a/gpsbabel/waypt.cc b/gpsbabel/waypt.cc index 27385e3e0..9425edc5c 100644 --- a/gpsbabel/waypt.cc +++ b/gpsbabel/waypt.cc @@ -122,7 +122,7 @@ waypt_add(Waypoint* wpt) wpt->shortname = wpt->notes; } else { QString n; - n.sprintf("%03d", waypt_ct); + n.sprintf("%03d", waypt_count()); wpt->shortname = QString("WPT%1").arg(n); } } @@ -144,7 +144,9 @@ waypt_add(Waypoint* wpt) void waypt_del(Waypoint* wpt) { + // the wpt must be on waypt_list, and is assumed unique. #if NEWQ + waypt_list.removeOne(wpt); #else dequeue(&wpt->Q); waypt_ct--; @@ -221,7 +223,7 @@ waypt_disp_session(const session_t* se, waypt_cb cb) if ((se == NULL) || (waypointp->session == se)) { if (global_opts.verbose_status) { i++; - waypt_status_disp(waypt_ct, i); + waypt_status_disp(waypt_count(), i); } (*cb)(waypointp); } @@ -324,8 +326,16 @@ find_waypt_by_name(const QString& name) void waypt_flush(queue* head) { - while (!waypt_list.isEmpty()) { - delete waypt_list.takeFirst(); +// TODO: This is incorrect when head != &waypt_head +// We need to pass in a QList instead of a queue* that we ignore! + if (head != &waypt_head) { + if (global_opts.debug_level >= 1) { + warning("NEWQ version of waypt_flush is unimplemented for this list.\n"); + } + } else { + while (!waypt_list.isEmpty()) { + delete waypt_list.takeFirst(); + } } } #else @@ -351,6 +361,8 @@ waypt_flush_all() mkshort_del_handle(&mkshort_handle); } #if NEWQ + // TODO: eventually we shoud pass the list instead of the queue. + waypt_flush(&waypt_head); #else waypt_flush(&waypt_head); #endif -- 2.30.2